<?
include("../includes/_functions.php");
$func=new func;
$doc = new DOMDocument( "1.0", 'UTF-8' );
$doc->formatOutput = true;
@$doc->load($file_xml);
$file_xml='autopro.xml';
if(file_exists($file_xml))
unlink($file_xml);

    $doc->appendChild($doc->createElement('keys'));
    $doc->save($file_xml);

$f = $doc->createDocumentFragment();
 
$data=$func->get_by_curl("http://autopro.channelvn.net/video/357/tong-hop-6.chn");
$n=0;
preg_match_all("#<a class=[\"']searchdate[\"'] href=[\"'](.*?)[\"']>(.*?)</a>#",$data,$page);
$number=explode("trang-",$page[1][count($page[0])-1]);
$number=explode(".chn",$number[1]);
$pages=intval($number[0]);

for($j=1;$j<=$pages;$j++){ 
    $link="http://autopro.channelvn.net/video/357/tong-hop-6/trang-$j.chn";
    $code=$func->get_by_curl($link); 
//	preg_match_all("#<td align=\"left\" valign=\"top\" class=\"videotd\">.*<div id=\"videobox\">(.*?)</div>.*</td>#i",$code,$r);
	$cut_num=explode('<td align="left" valign="top" class="videotd">',$code);
	for($i=1;$i<=count($cut_num);$i++){
	preg_match('#<a href=[\'"](.*?)[\'"] onclick =[\'"]ShowVideo\([\'"](.*?)[\'"],[\'"](.*?)[\'"],[\'"](.*?)[\'"],[\'"](.*?)[\'"],[\'"][\'"],[\'"][\'"],[\'"](.*?)[\'"]\)\; return false\;[\'"]>#i',$cut_num[$i],$par);
	preg_match("#<img alt='(.*?)' src='(.*?)'#i",$cut_num[$i],$par_img);


$n++;


$item = $doc->createElement('key');   
$node1=$doc->createElement('stt');
$item->appendChild($node1);
$so1=$doc->createCDATASection($n);
$node1->appendChild($so1);

$node2=$doc->createElement('id');
$item->appendChild($node2);
$so2=$doc->createCDATASection($par[3]);
$node2->appendChild($so2);


$node3=$doc->createElement('name');
$item->appendChild($node3);
$so3=$doc->createCDATASection($par[5]);
$node3->appendChild($so3);

$node4=$doc->createElement('location');
$item->appendChild($node4);
$so4=$doc->createCDATASection($par[2]);
$node4->appendChild($so4);


$node5=$doc->createElement('image');
$item->appendChild($node5);
$so5=$doc->createCDATASection($par_img[2]);
$node5->appendChild($so5);
	$f->appendChild($item);


	}
}
                                                                                 
 $doc->documentElement->appendChild($f);
 if($doc->save($file_xml))
echo "Ok";

?>